﻿using BPMN.Application.Contracts.BaseWay;
using BPMN.Application.Contracts.DTO.Response;
using BPMN.Application.IService;
using BPMN.Domain.Entity.Unit;
using BPMN.DomianShare;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BPMN.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UnitController : ControllerBase
    {
        private readonly IUnitService unit;

        public UnitController(IUnitService unit)
        {
            this.unit = unit;
        }

        /// <summary>
        /// 添加单位信息
        /// </summary>
        /// <param name="dto">单位信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddUnit(Units dto)
        {
            return Ok(await unit.AddUnit(dto));
        }

        /// <summary>
        /// 删除单位信息
        /// </summary>
        /// <param name="id">单位Id</param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> DeleleUnit(int id)
        {
            return Ok(await unit.DeleleUnit(id));
        }

        /// <summary>
        /// 分页、显示、查询单位信息
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页显示</param>
        /// <param name="name">单位名称</param>
        /// <param name="notes">单位备注</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetUnit(int pageIndex, int pageSize, string name, string notes)
        {
            return Ok(await unit.GetUnit(pageIndex, pageSize, name, notes));
        }

        /// <summary>
        /// 显示单位信息（用于下拉框显示）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetUnits()
        {
            return Ok(await unit.GetUnits());
        }

        /// <summary>
        /// 反填单位信息
        /// </summary>
        /// <param name="id">单位Id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetUnitById(int id)
        {
            return Ok(await unit.GetUnitById(id));
        }

        /// <summary>
        /// 修改单位信息
        /// </summary>
        /// <param name="dto">单位信息</param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> UpdateUnit(Units dto)
        {
            return Ok(await unit.UpdateUnit(dto));
        }
    }
}
